/**
 * 
 */
package com.ynet.middleground.riskmanage.mq.producer;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONArray;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.bean.ColdchainGoodsTypeReq;
import com.ynet.middleground.riskmanage.mq.SourceZt;

/**
 * @author songyf
 * @description 中台需要推送的其它业务部分数据
 * @date 2020-08-20 14:22
 */
@EnableBinding({SourceZt.class})
@Component
public class ZtProducer {
    @Autowired
    SourceZt sourceZt;
    
    /**
     * 给核心系统 MQ 推送冷链货种小类信息
     *
     * @param data 推送冷链货种小类信息
     */
    public void sendMessagesColdGoodsTypeIn(ColdchainGoodsTypeReq req,JSONArray data) {
        Map<String, Object> msgMap = new HashMap<>(3);
        msgMap.put("traceId", req.getTraceId());
        msgMap.put("requestTime", req.getRequestTime());
        msgMap.put("list", data);
        IfpLogger.info("mq", "推送冷链货种小类信息给核心系统，往 Binding-{} 推送信息-{}", SourceZt.JKZTFK_TO_BLXD_HWXL_IN, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.sourceZt.ColdchainGoosnotice().send(message);
    }
    
    /**
     * 给核心系统 MQ 推送大港货种信息
     *
     * @param jsonArray 推送大港货种信息
     */
    public void sendMessagesDgGoodsTypeIn(JSONArray jsonArray) {
        Map<String, Object> msgMap = new HashMap<>(2);
        msgMap.put("requestTime", LocalDateTime.now());
        msgMap.put("list", jsonArray);
        IfpLogger.info("mq", "推送大港货种信息给核心系统，往 Binding-{} 推送信息-{}", SourceZt.JKZTFK_TO_BLXD_HWDG_IN, msgMap);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msgMap, messageHeaders);
        this.sourceZt.DgGoodsnotice().send(message);
    }
}
